<?php
$email = "linda@linda.com.br";
$token = "EC5B5C789C0BF6852E79AA9E24F404C5";
//$url = "https://ws.pagseguro.uol.com.br/v2/checkout/?email=" . $email . "&token=" . $token;
$url = "http://localhost/sandbox/servico/entrada.php?email=" . $email . "&token=" . $token;
$xml = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" standalone=\"yes\"?>
    <checkout>
        <currency>BRL</currency>
        <redirectURL>http://www.minhaloja.com.br/retorno.php</redirectURL>
        <items>
            <item>
                <id>0001</id>
                <description>Notebook Prata</description>
                <amount>1.00</amount>
                <quantity>1</quantity>
                <weight>1000</weight>
            </item>
            <item>
                <id>0002</id>
                <description>Notebook Rosa</description>
                <amount>2.00</amount>
                <quantity>2</quantity>
                <weight>750</weight>
            </item>
        </items>
        <reference>REF1234</reference>
        <sender>
            <name>Jose Comprador</name>
            <email>sounoob@comprador.com.br</email>
            <phone>
                <areaCode>11</areaCode>
                <number>55663377</number>
            </phone>
        </sender>
        <shipping>
            <type>1</type>
            <address>
                <street>Rua sem nome</street>
                <number>1384</number>
                <complement>5o andar</complement>
                <district>Jardim Paulistano</district>
                <postalCode>24130286</postalCode>
                <city>Sao Paulo</city>
                <state>SP</state>
                <country>BRA</country>
            </address>
        </shipping>
    </checkout>";

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type: application/xml; charset=ISO-8859-1"));
curl_setopt($curl, CURLOPT_POSTFIELDS, $xml);
$xml = curl_exec($curl);
curl_close($curl);

//echo $xml;
$xml = simplexml_load_string($xml);

if(count($xml -> error) > 0){
    //header('Location: paginaDeErro.php');
	echo 'Erro';
    exit;
}

// Dando tudo certo, temos dois itens a ver:
// $xml->code, que contém o código da venda
// $xml->date, que contém a data + hora da venda

//header('Location: https://pagseguro.uol.com.br/v2/checkout/payment.html?code=' . $xml -> code);
//É o ideal: transfere direto, sem o usuário ter que clicar no link.
?>
<a href="http://localhost/sandbox/principal/pagamento.php?code=<?=$xml->code?>">Link para pagamento</a>